/*
 * @Copyright: Citylife 2021
 * @Author: shaokui.gu
 * @Date: 2020-12-14 12:48:48
 * @Description: 欢迎页
 */
import 'package:flutter/foundation.dart';
import 'package:permission_handler/permission_handler.dart';
import '../../app_starter.dart';
import '../../base/base.dart';
import '../../base/base_page.dart';
import '../../utils/locale/local_manager.dart';
import '../../utils/permission/permission_manager.dart';

class WelcomeController extends BaseController {
  WelcomeController() : super();

  @override
  void onInit() {
    super.onInit();
    AppStarter.initConfig();
    checkPermissions();
  }

  void onClose() {
    super.onClose();
  }

  ///  请求权限
  void checkPermissions() async {
    List<Permission> permissions = [];
    if (defaultTargetPlatform == TargetPlatform.android) {
      permissions = [Permission.phone];
    }

    if (permissions.length > 0) {
      PermissionManager.instance.requestPermissions(permissions, () async {
        _gotoMain();
      });
    } else {
      _gotoMain();
    }
  }

  void _gotoMain() {
    // 延时1s执行返回
    Future.delayed(Duration(seconds: 1), () {
      Get.offNamed("/main");
    });
  }
}

class WelcomePage extends BasePage<WelcomeController> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        color: Colors.white,
        child: Center(
          child: Text(
            appString.huanying,
            style: TextStyle(
              fontSize: 30.0.w,
              color: Colors.black,
            ),
          ),
        ),
      ),
    );
  }

  @override
  WelcomeController initController() {
    return WelcomeController();
  }
}
